/*
 * Copyright (c) 2023-7-31
 * 说明: 考场的信息类
 */

package ExamArea

import (
	"context"
	"feng-che.com/server/driver-quiz/internal/dep_db"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	"mongoDB"
	"time"
)

// ExamArea 考场的信息
type ExamArea struct {
	mongoDB.MongoDefaultModelNonID `bson:"basic"`
	ID                             primitive.ObjectID `bson:"_id,omitempty" json:"id"`
	Name                           string             `bson:"name" json:"name"`
	Address                        string             `bson:"address" json:"address"`
	Lat                            float64            `bson:"lat" json:"lat"`
	Lng                            float64            `bson:"lng" json:"lng"`
	Logo                           string             `bson:"logo" json:"logo"`
	Photos                         []string           `bson:"photos" json:"photos"`
	Introduce                      string             `bson:"introduce" json:"introduce"`
	WorkOn                         string             `bson:"workOn" json:"workOn"`
	WorkOff                        string             `bson:"workOff" json:"workOff"`
}

func (a *ExamArea) Save(ctx context.Context) (*mongo.UpdateResult, error) {
	a.UpdatedAt = time.Now()
	if a.ID.IsZero() {
		a.ID = primitive.NewObjectID()
	}
	updateResult, err := dep_db.ExamAreaCollection().UpdateByID(
		ctx,
		a.ID,
		bson.D{
			{"$set", a},
		},
		options.Update().SetUpsert(true),
	)
	return updateResult, err
}
